home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / borland / bgidriv.zip / DEBUG.C < prev    next >
Text File  |  1989-06-20  |  47KB  |  1,345 lines

  1.  
  2. /*
  3.  
  4.     DEBUG.C - sample debugging BGI driver
  5.  
  6.     Copyright (c) 1988,89 Borland International
  7.  
  8. */
  9.  
  10.  
  11.  
  12.  
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <dos.h>
  16.  
  17. /* ----------------------------- DEBUG.C ------------------------------ */
  18. /*                                                                      */
  19. /*      Function Protoypes for the debug driver.                        */
  20. /*                                                                      */
  21.  
  22. void save_regs( void );
  23. void banner( char *str );
  24. void putnum( unsigned number );
  25. void puthex( unsigned number );
  26. void dputs( char far *str );
  27. void crlf( void );
  28.  
  29. void far enter_graphics( void );
  30. void far leave_graphics( void );
  31. void far putpix( void );
  32. void far getpix( void );
  33. void far bits_per_pixel( void );
  34. void far set_visual( void );
  35. void far set_page( void );
  36. void far set_write_mode( void );
  37.  
  38. typedef void far (*FRFPTR)( void );     /* Pointer to Void/Void Funct   */
  39. typedef void     (*NRFPTR)( void );     /* Pointer to Void/Void Funct   */
  40.  
  41. /*                                                                      */
  42. /*      The following C structure defines a Device Status Block.        */
  43. /*                                                                      */
  44.  
  45. typedef struct {
  46.   unsigned char   stat;                 /* Current device status.       */
  47.   unsigned char   devtype;              /* Device Type Identifier.      */
  48.   unsigned int    xres;                 /* Device Full Resolution in X  */
  49.   unsigned int    yres;                 /* Device Full Resolution in Y  */
  50.   unsigned int    xefres;               /* Device Effective X Resolution*/
  51.   unsigned int    yefres;               /* Device Effective Y Resolution*/
  52.   unsigned int    xinch;                /* Device X Size in inches*1000 */
  53.   unsigned int    yinch;                /* Device Y Size in inches*1000 */
  54.   unsigned int    aspec;                /* Aspect Ratio * 10000         */
  55.   unsigned char   chsizx;               /* Standard char size X         */
  56.   unsigned char   chsizy;               /* Standard char size Y         */
  57.   unsigned char   fcolors;              /* Number of foreground colors  */
  58.   unsigned char   bcolors;              /* Number of background colors  */
  59. } STATUS;
  60.  
  61. /*                                                                      */
  62. /*      The following structure defines a palette record.               */
  63. /*                                                                      */
  64.  
  65. typedef struct {
  66.   unsigned char length;                 /* # of color entries in palette*/
  67.   unsigned char color[16];              /* Up to 16 color entries       */
  68.   } PALETTE;
  69.  
  70. /*                                                                      */
  71. /*      The following structure defines a utility function table.       */
  72. /*                                                                      */
  73.  
  74. typedef struct {
  75.   NRFPTR  goto_graph;                   /* Enter graphics mode function */
  76.   NRFPTR  exit_graph;                   /* Leave graphics mode function */
  77.   NRFPTR  putpix;                       /* Write a pixel function       */
  78.   NRFPTR  getpix;                       /* Read a pixel function        */
  79.   NRFPTR  bits_per_pixel;               /* Bits per pixel value         */
  80.   NRFPTR  set_page;                     /* Set the active drawing page  */
  81.   NRFPTR  set_visual;                   /* Set the active display page  */
  82.   NRFPTR  write_mode;                   /* Set the current write mode   */
  83.   } UTILITIES;
  84.  
  85. /*                                                                      */
  86. /*      This status block declares the debug driver to appear as an     */
  87. /*      EGA card in high resolution mode.                               */
  88. /*                                                                      */
  89.  
  90. STATUS  Stat_Block = {          /* Status block to fake an EGA driver   */
  91.   0,                            /* Current device status.               */
  92.   0,                            /* Device Type Identifier.              */
  93.   639,                          /* Device Full Resolution in X          */
  94.   479,                          /* Device Full Resolution in Y          */
  95.   639,                          /* Device Effective X Resolution        */
  96.   479,                          /* Device Effective Y Resolution        */
  97.   9000,                         /* Device X Size in inches*1000         */
  98.   7000,                         /* Device Y Size in inches*1000         */
  99.   10000,                        /* Aspect Ratio * 10000                 */
  100.   8  + 0x80,                    /* Standard char size X                 */
  101.   8  + 0x80,                    /* Standard char size Y                 */
  102.   16 + 0x80,                    /* Number of foreground colors          */
  103.   16 + 0x80                     /* Number of background colors          */
  104.   };
  105.  
  106. /*                                                                      */
  107. /*      This palette declares the default EGA palette.                  */
  108. /*                                                                      */
  109.  
  110. PALETTE Default_Palette = {     /* Define the palette for above EGA mode*/
  111.   16, { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
  112.         0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F  }
  113.   };
  114.  
  115. /*                                                                      */
  116. /*      The following structure defines the Bit Manipulation Utility    */
  117. /*      function table.                                                 */
  118. /*                                                                      */
  119.  
  120. UTILITIES Utility_Table = {             /* Bit Utilities Function Table */
  121.   (NRFPTR) enter_graphics,              /* Enter graphics mode function */
  122.   (NRFPTR) leave_graphics,              /* Leave graphics mode function */
  123.   (NRFPTR) putpix,                      /* Write a pixel function       */
  124.   (NRFPTR) getpix,                      /* Read a pixel function        */
  125.   (NRFPTR) bits_per_pixel,              /* Bits per pixel function      */
  126.   (NRFPTR) set_page,                    /* Set the active drawing page  */
  127.   (NRFPTR) set_visual,                  /* Set the active display page  */
  128.   (NRFPTR) set_write_mode               /* Set the current write mode   */
  129.   };
  130.  
  131. /*                                                                      */
  132. /*      The following defines the name of the modes for Driver.         */
  133. /*      NOTE: The string must start with a PASCAL style length.         */
  134. /*                                                                      */
  135.  
  136. char Name[] = "\030Debug Driver (640 x 480)";
  137.  
  138. /*      Driver Local Data Variables                                     */
  139.  
  140. char Buffer[80] = { 0 };                /* String output buffer         */
  141.  
  142. unsigned int    CP_X = 0, CP_Y = 0;     /* Current Drawing Pointer CP   */
  143.  
  144. unsigned int  ds = 0;                   /* DS on entry to the driver    */
  145. unsigned int  ax = 0, bx = 0, cx = 0, dx = 0;
  146. unsigned int  ah = 0, bh = 0, ch = 0, dh = 0;
  147. unsigned int  al = 0, bl = 0, cl = 0, dl = 0;
  148.  
  149. /* ----------------------------- INSTALL ------------------------------- */
  150. /*                                                                       */
  151. /*      The Install function is used to prepare the driver to use.       */
  152. /*      The calls to this function allow the kernal to inquire the       */
  153. /*      mode information, and allow the kernal to install the mode       */
  154. /*      infomation.                                                      */
  155. /*                                                                       */
  156.  
  157. void install( void )
  158. {
  159.  
  160.   save_regs();                          /* Save a copy of current regs  */
  161.  
  162.   banner( "INSTALL" );                  /* Announce the function type   */
  163.   switch( al ){                         /* Determine the command to use */
  164.  
  165.     case 0:                             /* Install Device Command       */
  166.       dputs( "    Install Device:   Mode Number: " );
  167.       putnum( cl );
  168.       dputs( "  AutoDetect Maxi